# @Time: 2021/3/4 0:13
# @Athuor: 雷磊
# @Email: 1021010830@qq.com
# @File: run.py
import unittest
from HTMLTestReportCN import HTMLTestRunner
from BeautifulReport import BeautifulReport
import time
from setting import CASE_PATH


discover = unittest.defaultTestLoader.discover(CASE_PATH, pattern="test_Upload*.py")


def html_test_runner(report_title, description, tester):
    """
    使用 HTMLTestRunner生成html测试报告
    :param report_title: 报告标题
    :param description: 报告描述
    :param tester: 测试者
    :return: xxx.html报告文件
    """

    now = time.strftime("%Y-%m-%d %H-%M-%S")
    f = open("../report/crm_report_{}.html".format(now), "wb")
    runner = HTMLTestRunner(stream=f, title=report_title, description=description, tester=tester)
    runner.run(discover)


def beautiful_report(filename, description: str='测试报告'):
    """
    使用BeautifulReport生成html测试报告
    :param report_dir: 生成report的文件存储路径
    :param filename: 生成文件的filename
    :param description: 生成文件的注释
    :return: xxx.html报告文件
    """
    now = time.strftime("%Y-%m-%d %H-%M-%S")
    file_name = filename + "_report_{}".format(now)
    BeautifulReport(discover).report(filename=file_name, description=description, report_dir='../report')


if __name__ == '__main__':
    beautiful_report('小白接口', '小白接口')